/*
<Copyright (C) 2011 Dru Moore>

This file is part of demorecorder.

vlc-remote is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

demorecorder is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with demorecorder.  If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 1.1
import com.meego 1.0

Item {
    id:root
    width: parent.width
    height: 120
    anchors.margins: 4

    property int buttonSize: 60

    signal muteChanged(bool muted)
    signal activeChanged(bool active)
    signal settingChanged(string setting, variant newValue)
    signal clicked()
    signal doubleClicked()
    signal deleteClicked()
    signal nameUpdated(string newName)

    property alias textColor: titleText.color

    property string name: "Untitled"
    property alias active: activeCheck.checked
    property bool muted: false
    property double volume: 1.0
    property string iconType: ""
    onIconTypeChanged: {
        switch (iconType) {
        case "image":
            icon.source = "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-gallery-white.png";
            break;
        case "audio":
            icon.source = "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-content-audio-white.png";
            break;
        case "video":
            icon.source = "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-content-gallery.svg";
            break;
        case "file":
            icon.source = "file:///usr/share/themes/blanco/meegotouch/icons/icon-s-status-invitation-pending.png";
            break;
        case "favourite":
            icon.source = "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-favorite-mark-white.png";
            break;
        case "heart":
            icon.source = "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-frequent-used-white.png";
            break;

        }
    }

    VolumePanControl {
        id: volumePanControl
        visible: false
        width: root.width
        height: root.height
        x: 0
        y: 0
        z: 20
        onCloseClicked: {
            visible = false;
        }
    }

    Menu {
        id: optionsMenu
        MenuLayout {
            MenuItem {
                id: menuRename
                text: qsTr("Rename track")
                onClicked: {
                    dialogRename.open();
                    optionsMenu.close();
                }
            }
            MenuItem {
                id: menuDelete
                text: qsTr("Delete track")
                onClicked: {
                    dialogConfirmDelete.open();
                    optionsMenu.close();
                }
            }
        }
    }

    QueryDialog {
        id: dialogRename
        titleText: qsTr("Renaming track")
        content:  TextField {
            id: newName
            placeholderText: name
            text: name
        }
        acceptButtonText: qsTr("Save")
        onAccepted: {
            name = newName.text
            nameUpdated(newName.text);
        }
        rejectButtonText: qsTr("Undo")
    }

    QueryDialog {
        id: dialogConfirmDelete
        property alias message:  message.text
        titleText: qsTr("Really delete?")
        content:  Text {
            id: message
            width:  parent.width
            wrapMode: "WrapAtWordBoundaryOrAnywhere"
            maximumLineCount: 6
            font.pixelSize: 24
            color: "white"
            text:  qsTr("Do you want to delete <b>") + name + "</b>?"
        }
        acceptButtonText: qsTr("Yes, delete it")
        onAccepted: {
            deleteClicked();
        }
        rejectButtonText: qsTr("No, keep it")
    }

    ButtonStyle {
        id: textButtonStyle
        fontPixelSize: 32
        fontWeight: Font.Bold
        textColor: "#ffffff"
    }

    MouseArea {
        anchors.fill: parent
        onClicked:{
            root.clicked()

        }
        onDoubleClicked:{
            root.doubleClicked()

        }
    }

    Row {

        Image {
            id: icon
            source: "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-frequent-used-white.png";
            sourceSize.width: buttonSize + 8
            sourceSize.height: buttonSize + 8
            width: buttonSize + 8
            height: buttonSize + 8
            anchors.verticalCenter: parent.verticalCenter
        }

        Column {

            Row {
                id: textRow
                spacing: 12

                Text {
                    id: titleText
                    //width: 150
                    text: name
                    font.pixelSize: 36
                    font.letterSpacing: -2
                    color: "#ffffff"
                }

            }

            Row {
                id: buttonRow

                Grid {

                    id: trackLayout
                    rows: 1
                    columns: 5
                    spacing: 20


                    CheckBox {
                        id: activeCheck
                        checked: true
                        onCheckedChanged: activeChanged(checked)
                    }

                    Button {
                        id: buttonMute
                        width:  buttonSize
                        height: buttonSize
                        enabled: active
                        iconSource: muted ? "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-volume-off-white.png" : "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-volume-off-dimmed-white.png"
                        onClicked: {
                            muted = !muted;
                            muteChanged(!muted);
                        }
                    }
                    Button {
                        id: buttonVolume
                        width:  buttonSize
                        height: buttonSize
                        enabled: active
                        iconSource: "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-volume-white.png"
                        onClicked: {
                            volumePanControl.visible = !volumePanControl.visible;
                        }
                    }

                    Button {
                        id: buttonFx
                        width:  buttonSize
                        height: buttonSize
                        enabled: active
                        text:  "fx"
                        platformStyle: textButtonStyle
                        //iconSource: muted ? "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-telephony-volume.svg" : "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-volume-off-white.png"
                        onClicked: {

                        }
                    }

                    Button {
                        id: buttonSettings
                        width:  buttonSize
                        height: buttonSize
                        enabled: active
                        iconSource: "file:///usr/share/themes/blanco/meegotouch/icons/icon-m-toolbar-view-menu-white.png"
                        onClicked: {
                            // launchSettings
                            optionsMenu.open();
                        }
                    }

                }

            }

        }

    }

}
